from socket import *

FREE_ANGLE=181
SERVO_NUM = 80
ADRESS_TABLE = []

HOST = '192.168.1.103' # or 'localhost'
PORT = 5050
ADDR = (HOST,PORT)
 
class servo_rmt_c():
    def __init__(self, num = SERVO_NUM, address = ADRESS_TABLE):
        self.tcpCliSock = socket(AF_INET,SOCK_STREAM)
        self.tcpCliSock.connect(ADDR)

    def _run_to(self, idx, angle):
        ctlStr = "servoCtl.set_angle({}, {}, {}, {})\n".format(idx, angle, speed, True)
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

####################################################
    def set_angle(self, idx, angle, speed = 0, update = False):
        ctlStr = "servoCtl.set_angle({}, {}, {}, {})\n".format(idx, angle, speed, update)
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

    def play_note(self, note, update = False):
        ctlStr = "servoCtl.set_angle({}, {}, {}, {})\n".format(idx, angle, speed, update)
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

    def update(self):
        ctlStr = "servoCtl.update()\n"
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

servoCtl = servo_rmt_c()
